package com.share.hope.controller;

import com.share.hope.entity.PostsInfo;
import com.share.hope.entity.page.PageQueryVo;
import com.share.hope.entity.result.PageR;
import com.share.hope.entity.result.R;
import com.share.hope.service.PostsInfoService;
import com.share.hope.vo.PostsPageQueryVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/share/hope/posts")
@RequiredArgsConstructor
@Slf4j
@Tag(name = "论坛信息管理接口")
@CrossOrigin
public class PostsInfoController {

    private final PostsInfoService postsInfoService;

    @PostMapping("/create")
    @Operation(summary = "发表帖子")
    public R<String> createPostsInfo(@RequestBody PostsInfo postsInfo) {
        return postsInfoService.createPostsInfo(postsInfo);
    }

    @PostMapping("/update")
    @Operation(summary = "修改帖子")
    public R<String> updatePostsInfo(@RequestBody PostsInfo postsInfo) {
        return postsInfoService.updatePostsInfo(postsInfo);
    }

    @GetMapping("/delete")
    @Operation(summary = "删除帖子")
    public R<String> deletePostsInfo(@RequestParam Long id) {
        return postsInfoService.deletePostsInfo(id);
    }

    @PostMapping("/page")
    @Operation(summary = "分页查询帖子")
    public R<PageR<PostsInfo>> pagePostsInfo(@RequestBody PageQueryVo<PostsPageQueryVo> queryVo) {
        return postsInfoService.pagePostsInfo(queryVo);
    }

}
